package net.wicp.tams.commons.binlog.constant;

/***
 * TYPE_SET: ENUM: STRING: metadata[i] = CodecUtils.toInt(d.readBytes(2), 0, 2);
 * // Big-endian break;
 * 
 * @author Administrator
 *
 */
public enum ColumnType {
	DECIMAL("", (byte) 0x00, 2),

	TINY("", (byte) 0x01, 0,1),

	SHORT("", (byte) 0x02, 0,2),

	LONG("", (byte) 0x03, 0,4),

	FLOAT("", (byte) 0x04, 1,4),

	DOUBLE("", (byte) 0x05, 1,8),

	NULL("", (byte) 0x06),  //stored in the NULL-bitmap only

	TIMESTAMP("", (byte) 0x07, 0),

	LONGLONG("", (byte) 0x08, 0,8),

	INT24("", (byte) 0x09, 0,4),

	DATE("", (byte) 0x0a, 0),

	TIME("", (byte) 0x0b), // -----

	DATETIME("", (byte) 0x0c, 0),

	YEAR("", (byte) 0x0d),

	NEWDATE("", (byte) 0x0e),

	VARCHAR("", (byte) 0x0f, 2), // 2个字节，存储的是string的长度

	BIT("", (byte) 0x10, 0),

	TIMESTAMP2("", (byte) 0x11),

	DATETIME2("", (byte) 0x12),

	TIME2("", (byte) 0x13), // 过于复杂，不管

	NEWDECIMAL("", (byte) 0xf6, 2), // 过于复杂，不管

	ENUM("", (byte) 0xf7, 2),

	SET("", (byte) 0xf8), // see MYSQL_TYPE_ENUM

	TINY_BLOB("", (byte) 0xf9),

	MEDIUM_BLOB("", (byte) 0xfa),

	LONG_BLOB("", (byte) 0xfb),

	BLOB("", (byte) 0xfc, 1), // 1个字节得到值，1：表明是tiny blob,第1个字节存储blob长度, 2:short
								// blob 前2个字节存blob长度

	VAR_STRING("", (byte) 0xfd, 2),

	STRING("", (byte) 0xfe, 2),

	GEOMETRY("", (byte) 0xff);

	private final String desc;
	private final byte value;// 值
	private final int metaLen;
	private final int colLen;

	public static ColumnType get(byte val) {
		if (val > 0xff) {
			return null;
		}
		for (ColumnType columnType : ColumnType.values()) {
			if (columnType.getValue() == val) {
				return columnType;
			}
		}
		return null;
	}

	private ColumnType(String desc, byte value, int metaLen, int colLen) {
		this.desc = desc;
		this.value = value;
		this.metaLen = metaLen;
		this.colLen = colLen;
	}

	private ColumnType(String desc, byte value, int metaLen) {
		this.desc = desc;
		this.value = value;
		this.metaLen = metaLen;
		this.colLen = -1;
	}

	private ColumnType(String desc, byte value) {
		this.desc = desc;
		this.value = value;
		this.metaLen = -1;
		this.colLen = -1;
	}

	public String getDesc() {
		return desc;
	}

	public byte getValue() {
		return value;
	}

	public int getMetaLen() {
		return metaLen;
	}

	public int getColLen() {
		return colLen;
	}

}
